require("../../utils/util.js");

var e = require("../../requests/request.js"), a = getApp();

Page({
    data: {
        cars: {},
        masterId: 0,
        loading: !1,
        initails: [],
        name: ""
    },
    onLoad: function(e) {
        var a = e.id, r = e.name;
        console.log("---masterid-------" + a), this.setData({
            masterId: a,
            name: r
        });
    },
    onReady: function() {
        this.loadBrandData();
    },
    loadBrandData: function() {
        var a = this;
        a.setData({
            loading: !0
        }), wx.setNavigationBarTitle({
            title: this.data.name
        }), e.getSerialList(this.data.masterId, function(e) {
            console.log(e);
            for (var r = [], t = [], n = [], i = 0; i < e.length - 1; i++) {
                if (e[i].Picture && (e[i].Picture = e[i].Picture.replace("{0}", 6)), r.contains2(e[i].BrandName) || r.push(e[i].BrandName), 
                "" != e[i].DealerPrice && "暂无报价" != e[i].DealerPrice || (e[i].DealerPrice = e[i].ReferPrice), 
                "暂无" == e[i].DealerPrice && (e[i].DealerPrice = "暂无报价"), e[i].DealerPrice && e[i].DealerPrice.indexOf("-")) {
                    var o = e[i].DealerPrice.split("-");
                    o && o.length > 1 && o[0] == o[1] && (e[i].DealerPrice = o[0]);
                }
                e[i].PriceName = e[i].DealerPrice;
            }
            r.forEach(function(a) {
                var r = e.filter(function(e) {
                    return e.BrandName == a;
                }).sort(function(e, a) {
                    return a.UV - e.UV;
                });
                console.log("----new sorted array----"), t.push({
                    Name: r[0].BrandName,
                    Uv: r[0].UV
                });
            }), t.sort(function(e, a) {
                return a.Uv - e.Uv;
            }), console.log(t);
            for (i = 0; i < t.length; i++) n.push(t[i].Name);
            a.setData({
                cars: e.slice(0, e.length - 1).sort(function(e, a) {
                    return a.UV - e.UV;
                }),
                initails: n
            });
        }, null, function() {
            a.setData({
                loading: !1
            });
        });
    },
    onPullDownRefresh: function() {
        this.loadBrandData(), wx.stopPullDownRefresh();
    },
    bindJump: function(e) {
        var a = e.currentTarget.dataset.id, r = e.currentTarget.dataset.name;
        console.log(a), wx.navigateTo({
            url: "../summary/summary?id=" + a + "&name=" + r
        });
    },
    returnBtn: function() {
        a.gotoIndex();
    }
}), Array.prototype.contains2 = function(e) {
    for (var a in this) if (this[a] == e) return !0;
    return !1;
};